//
//  SLRootViewControllerConfig.m
//  StarLight
//
//  Created by 吴涛 on 16/5/9.
//  Copyright © 2016年 Duke.Wu. All rights reserved.
//

#import "SLRootViewControllerConfig.h"
#import "SLNearViewController.h"
#import "SLDeployViewController.h"
#import "SLFriendViewController.h"
#import "SLInformationViewController.h"
#import "SLMineViewController.h"
#import "SLLoginViewController.h"
#import "SLBaseTabBarController.h"
#import "SLNewMineViewController.h"
#import "SLHomeViewController.h"
#import "SLUserShipownerViewController.h"
#import "LLTabBar.h"


@interface SLRootViewControllerConfig ()<LLTabBarDelegate>

@end


@implementation SLRootViewControllerConfig


- (UINavigationController *)tabbarNav{
    
    if (!_tabbarNav) {
        
    SLHomeViewController *homeViewController = [[SLHomeViewController alloc] init];
    SLDeployViewController *sameCityViewController = [[SLDeployViewController alloc] init];
    SLInformationViewController *messageViewController = [[SLInformationViewController alloc] init];
    SLNewMineViewController *mineViewController = [[SLNewMineViewController alloc] init];
    
    UITabBarController *tabBarController = [[UITabBarController alloc] init];
    tabBarController.viewControllers = @[homeViewController, sameCityViewController, messageViewController, mineViewController];
    
    [[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];
    [[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
    
    LLTabBar *tabBar = [[LLTabBar alloc] initWithFrame:tabBarController.tabBar.bounds];
    tabBar.tabBarItemAttributes = @[@{kLLTabBarItemAttributeTitle : @"首页", kLLTabBarItemAttributeNormalImageName : @"ic_tab_shouye_nor", kLLTabBarItemAttributeSelectedImageName : @"ic_tab_shouye_sel", kLLTabBarItemAttributeType : @(LLTabBarItemNormal)},
                                    @{kLLTabBarItemAttributeTitle : @"配载", kLLTabBarItemAttributeNormalImageName : @"recommend-1", kLLTabBarItemAttributeSelectedImageName : @"recommend", kLLTabBarItemAttributeType : @(LLTabBarItemNormal)},
                                    @{kLLTabBarItemAttributeTitle : @"", kLLTabBarItemAttributeNormalImageName : @"post_normal", kLLTabBarItemAttributeSelectedImageName : @"post_normal", kLLTabBarItemAttributeType : @(LLTabBarItemRise)},
                                    @{kLLTabBarItemAttributeTitle : @"资讯", kLLTabBarItemAttributeNormalImageName : @"information-1", kLLTabBarItemAttributeSelectedImageName : @"information", kLLTabBarItemAttributeType : @(LLTabBarItemNormal)},
                                    @{kLLTabBarItemAttributeTitle : @"我的", kLLTabBarItemAttributeNormalImageName : @"my-1", kLLTabBarItemAttributeSelectedImageName : @"my", kLLTabBarItemAttributeType : @(LLTabBarItemNormal)}];
    tabBar.delegate = self;
    [tabBarController.tabBar addSubview:tabBar];
        
        _tabbarNav = [[UINavigationController alloc] initWithRootViewController:tabBarController];
        [_tabbarNav setNavigationBarHidden:YES animated:YES];
    }
    return _tabbarNav;

}

#pragma mark - LLTabBarDelegate

- (void)tabBarDidSelectedRiseButton {
//    UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
//    UIViewController *viewController = tabBarController.selectedViewController;
//    
//    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
//                                                             delegate:self
//                                                    cancelButtonTitle:@"取消"
//                                               destructiveButtonTitle:nil
//                                                    otherButtonTitles:@"拍照", @"从相册选取", @"淘宝一键转卖", nil];
//    [actionSheet showInView:viewController.view];
}


- (UINavigationController *)tabbarNavi{
  if (!_tabbarNavi) {
      
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
      
    SLHomeViewController *nearVC = [SLHomeViewController new];
//    [nearVC.naviHeader setNaviTitleWithString:@"首页"];
    nearVC.title = @"首页";
    nearVC.tabBarItem.image = [[UIImage imageNamed:@"ic_tab_shouye_nor"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
    nearVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"ic_tab_shouye_sel"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
    
    SLDeployViewController *deployVC = [SLDeployViewController new];
    [deployVC.naviHeader setNaviTitleWithString:@"配载"];
    deployVC.title = @"配载";
    deployVC.tabBarItem.image = [[UIImage imageNamed:@"recommend-1"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
    deployVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"recommend"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
    
    SLFriendViewController *friendVC = [SLFriendViewController new];
//      SLUserShipownerViewController *friendVC = [SLUserShipownerViewController new];
      
      
    [friendVC.naviHeader setNaviTitleWithString:@"好友"];
//    friendVC.title = @"好友";
//    friendVC.tabBarItem.image = [[UIImage imageNamed:@"Friends-1"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
//    friendVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"Friends"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
      friendVC.tabBarItem.image = [[UIImage imageNamed:@""] imageWithRenderingMode:UIImageRenderingModeAutomatic];
      friendVC.tabBarItem.selectedImage = [[UIImage imageNamed:@""] imageWithRenderingMode:UIImageRenderingModeAutomatic];
    
    
    SLInformationViewController *informationVC = [SLInformationViewController new];
    [informationVC.naviHeader setNaviTitleWithString:@"资讯"];
    informationVC.title = @"资讯";
    informationVC.tabBarItem.image = [[UIImage imageNamed:@"information-1"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
    informationVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"information"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
    
    
    SLNewMineViewController *mineVC = [SLNewMineViewController new];
    [mineVC.naviHeader setNaviTitleWithString:@"我的"];
    mineVC.title = @"我的";
    mineVC.tabBarItem.image = [[UIImage imageNamed:@"my-1"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
    mineVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"my"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
    
    SLBaseTabBarController *tabarvc = [[SLBaseTabBarController alloc] init];
    [tabarvc setViewControllers:@[nearVC,deployVC,friendVC,informationVC,mineVC] animated:YES];
    tabarvc.tabBar.tintColor = SLYellowColor;
    
    _tabbarNavi = [[UINavigationController alloc] initWithRootViewController:tabarvc];
    [_tabbarNavi setNavigationBarHidden:YES animated:YES];
  }
  return _tabbarNavi;
}


- (UINavigationController *)loginNavi{
  if (!_loginNavi) {
    SLLoginViewController *loginVC = [SLLoginViewController new];
    loginVC.title = @"登录";
    _loginNavi = [[UINavigationController alloc] initWithRootViewController:loginVC];
    NSDictionary *dic = [NSDictionary dictionaryWithObject:SLYellowColor forKey:NSForegroundColorAttributeName];
    [_loginNavi.navigationBar setTitleTextAttributes:dic];
    
  }
  return _loginNavi;
}


@end
